import 'package:flutter01/pages/sqfLite/sqflite_manager.dart';
import 'package:sqflite/sqflite.dart';

abstract class BaseTableProvider {

   final String _tableName;

   BaseTableProvider(this._tableName);

  String get tableName=>_tableName;

  String createTableString();

  /// 获取当前数据库对象
  Future<Database> getDataBase() async{
    bool isTableExists = await  SqlManager.isTableExists(tableName);
    if(!isTableExists){
      // 表不存在，则创建表
      Database db = await SqlManager.getCurrentDataBase();
      await db.execute(createTableString());
      return db;
    }else{
      return await SqlManager.getCurrentDataBase();
    }
  }

  /// 创建表
  Future<void> createTable() async {
    bool isTableExists = await  SqlManager.isTableExists(tableName);
    if(!isTableExists){
      // 表不存在，则创建表
      Database db = await SqlManager.getCurrentDataBase();
      await db.execute(createTableString());
    }
  }

}